package user_interface;

import javax.swing.JComboBox;

public class ComboItem {
    private String key;
    private int value;

    public ComboItem(String key, int value)
    {
        this.key = key;
        this.value = value;
    }

    @Override
    public String toString()
    {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public String getKey()
    {
        return key;
    }

    public int getValue()
    {
        return value;
    }
    
    
    public static void setSelectedValue(JComboBox comboBox, int value)  // chuyển mã sang index
    {
        ComboItem item;
        for (int i = 0; i < comboBox.getItemCount(); i++)
        {
            item = (ComboItem)comboBox.getItemAt(i);
            if (item.getValue() == value)
            {
                comboBox.setSelectedIndex(i);
                break;
            }
        }
    }
}
